<%@ page import="pl.dmcs.grails.Employee" %>

<g:set var="isAdmin" value="${false}" />
<sec:access expression="hasRole('ROLE_DMCS_ADMIN')">
    <g:set var="isAdmin" value="${true}" />
</sec:access>

<div class="fieldcontain ${hasErrors(bean: employeeInstance, field: 'avatar', 'error')}">
    <g:if test="${employeeInstance.avatar}">
        <div class="img-container">
            <img class="form-img" src="${createLink(controller:'employee', action:'getAvatar', id:employeeInstance.id )}" />
        </div>
    </g:if>
    <label for="avatar"> <g:message code="employee.avatar.label" default="Avatar" /></span>
    </label> <input type="file" name="avatarInput" id="avatar" />
</div>

<div class="fieldcontain ${hasErrors(bean: employeeInstance, field: 'username', 'error')} required">
    <label for="username"> 
        <g:message code="employee.username.label" default="Username" /> 
        <span class="required-indicator">*</span>
    </label>
    <g:textField name="username" required="" value="${employeeInstance?.username}" />
</div>

<sec:ifLoggedIn>
    <g:if test="${employeeInstance?.id?.toString() == sec.loggedInUserInfo(field: 'id')?.toString() || isAdmin}">
        <g:if test="${employeeInstance.id == null}">
            <div class="fieldcontain required">
                <label for="pass">
                    <g:message code="employee.password.label" default="Password" />
                    <span class="required-indicator">*</span>
                </label>
                <g:passwordField name="pass" required="" autocomplete="off"/>
            </div>
            <div class="fieldcontain required">
                <label for="passwordConfirm">
                    <g:message code="employee.passwordConfirm.label" default="Password Confirmation" />
                    <span class="required-indicator">*</span>
                </label>
                <g:passwordField name="passwordConfirm" required="" autocomplete="off"/>
            </div>
        </g:if>
        <g:else>
            <div class="fieldcontain">
                <label for="pass"> 
                    <g:message code="employee.password.label" default="Password" />
                </label>
                <g:passwordField name="pass" value="" autocomplete="off"/>
            </div>
            <div class="fieldcontain">
                <label for="passwordConfirm"> <g:message code="employee.passwordConfirm.label" default="Password Confirmation" />
                </label>
                <g:passwordField name="passwordConfirm" value="" autocomplete="off"/>
            </div>
        </g:else>
    </g:if>
</sec:ifLoggedIn>

<div class="fieldcontain ${hasErrors(bean: employeeInstance, field: 'firstName', 'error')} required">
    <label for="firstName">
        <g:message code="employee.firstName.label" default="First Name" />
        <span class="required-indicator">*</span>
    </label>
    <g:textField name="firstName" required="" value="${employeeInstance?.firstName}"/>
</div>

<div class="fieldcontain ${hasErrors(bean: employeeInstance, field: 'lastName', 'error')} required">
    <label for="lastName">
        <g:message code="employee.lastName.label" default="Last Name" />
        <span class="required-indicator">*</span>
    </label>
    <g:textField name="lastName" required="" value="${employeeInstance?.lastName}"/>
</div>

<div class="fieldcontain ${hasErrors(bean: employeeInstance, field: 'email', 'error')} required">
    <label for="email">
        <g:message code="employee.email.label" default="Email" />
        <span class="required-indicator">*</span>
    </label>
    <g:field type="email" name="email" required="" value="${employeeInstance?.email}"/>
</div>

<div class="fieldcontain ${hasErrors(bean: employeeInstance, field: 'title', 'error')} ">
    <label for="title">
        <g:message code="employee.title.label" default="Title" />
    </label>
    <g:textField name="title" value="${SecurityRole?.title}"/>
</div>

<div class="fieldcontain ${hasErrors(bean: employeeInstance, field: 'room', 'error')} required">
    <label for="room">
        <g:message code="employee.room.label" default="Room" />
        <span class="required-indicator">*</span>
    </label>
    <g:textField name="room" required="" value="${employeeInstance?.room}"/>
</div>

<g:if test="${isAdmin}">
	<div class="fieldcontain ${hasErrors(bean: employeeInstance, field: 'authorities', 'error')} ">
		<label for="employeeRoles">
			<g:message code="employeeCategory.employee.roles" default="Roles" />
		
		</label>
		<g:select name="employeeRoles" from="${pl.dmcs.grails.security.SecurityRole.list()}" multiple="multiple" optionKey="id" optionValue="authority" size="5" value="${employeeInstance?.id ? employeeInstance.authorities*.id : ''}" class="many-to-many"/>
	</div>
</g:if>

